The length() method of the String class returns the length of the specified String.
// Java example of String length() Methods
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.length()); } }
Output:
8
The charAt() method of the String class returns the character at the given index.
// Java example of String charAt() Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.charAt(1)); } }
Output:
x
The substring method of the String class return the substring from the ith index character to end.
// Java example of String substring Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.substring(3)); } }
Output:
mDeva
The substring method of the String class return the substring (int start, int end) from the ith index character to end.
// Java example of String substring (int start, int end) Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.substring(3,5)); } }
Output:
mD
The concat method of the String class return the concatenates specified string to the end of this string.
// Java example of String concat Method
public class Main { public static void main(String args[]){ String s="Exam"; String s1="Deva"; System.out.println(s.concat(s1)); } }
Output:
DockerTpoint
The indexOf method of the String class returns the position of the first instance of the specified string within the given string.
// Java example of String indexOf Method
public class Main { public static void main(String args[]){ String s="Exam Deva"; System.out.println(s.indexOf("Deva")); } }
Output:
5
The indexOf (String string, int index) method of the String class returns the first instance of the specified string in the string, starting at the specified index.
// Java example of String indexOf Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.indexOf("De",3)); } }
Output:
4
The lastIndexOf method of the String class the last instance of the specified string, at the specified index, is returned.
// Java example of String lastIndexOf Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.indexOf("De")); } }
Output:
4
The equals method of the String class the string is compared to the given object.
// Java example of String equals Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.equals("DockerTpoint")); } }
Output:
true
The equalsIgnoreCase method of the String class the string is compared to the given string ignoring case considerations.
// Java example of String equalsIgnoreCase Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.equalsIgnoreCase("dockertpoint")); } }
Output:
true
The toLowerCase() method of the String class Lowercases each character in the String.
// Java example of String toLowerCase() Method
public class Main { public static void main(String args[]){ String s="EXAMDEVA"; System.out.println(s.toLowerCase()); } }
Output:
dockertpoint
The toUpperCase() method of the String class UpperCase each character in the String.
// Java example of String toUpperCase() Method
public class Main { public static void main(String args[]){ String s="dockertpoint"; System.out.println(s.toUpperCase()); } }
Output:
EXAMDEVA
The trim() method of the String class removes the whitespace at both ends and then returns a copy of the String. The middle whitespaces are unaffected.
// Java example of String trim() Method
public class Main { public static void main(String args[]){ String s=" exam deva "; System.out.println(s.trim()); // "exam deva" } }
Output:
exam deva
The replace method of the String class replaces every instance of old with new to produce a new string.
// Java example of String replace Method
public class Main { public static void main(String args[]){ String s="DockerTpoint"; System.out.println(s.replace('e','d')); } }
Output:
ExamDdva
Post your comment